﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace tools.Tooling
{
    class ScreenTool
    {
        public void SetScreen(ScreenEnum screenEnum)
        {
            switch (screenEnum)
            {
                case ScreenEnum.restore:
                    OnClickRestore();
                    break;
                case ScreenEnum.min:
                    OnClickMinimize();
                    break;
                case ScreenEnum.max:
                    OnClickMinimize();
                    break;
                default:
                    break;
            }
        }

        //通过非托管方式导入dll。这里是导入user32.dll。
        [DllImport("user32.dll")]
        public static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);
        [DllImport("user32.dll")]
        static extern IntPtr GetForegroundWindow();

        const int SW_SHOWMINIMIZED = 2; //{最小化, 激活}  
        const int SW_SHOWMAXIMIZED = 3;//最大化  
        const int SW_SHOWRESTORE = 1;//还原  
        public void OnClickMinimize()
        {
            //最小化   
            ShowWindow(GetForegroundWindow(), SW_SHOWMINIMIZED);
        }

        public void OnClickMaximize()
        {
            //最大化  
            ShowWindow(GetForegroundWindow(), SW_SHOWMAXIMIZED);
        }

        public void OnClickRestore()
        {
            //还原  
            ShowWindow(GetForegroundWindow(), SW_SHOWRESTORE);
        }
    }
}
